package com.zz.cc.business.app;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zz.cc.business.R;
import com.zz.common.app.BaseActivity;
import com.zz.common.widget.ZListView;

public class OtherActivity extends BaseActivity implements OnItemClickListener{
	
	private ZListView mListView;
	private SettingAdapter mAdapter;
	private final List<Integer> mSettingsId = new ArrayList<Integer>();
	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_other);
		initUI();
		fillView();
		refresh();
	}
	
	private void initUI() {
		mListView = (ZListView) findViewById(R.id.settings_list_view);
	}
	
	private void fillView() {
		mAdapter = new SettingAdapter();
		mListView.setAdapter(mAdapter);
	}
	
	private void refresh() {
		mSettingsId.clear();
		mSettingsId.add(R.string.settings_modify_business_detail);
		mSettingsId.add(R.string.settings_query_bill);
		mSettingsId.add(R.string.settings_publish_info);
		mSettingsId.add(R.string.settings_modify_base_info);
		
		mAdapter.notifyDataSetChanged();
	}
	
	@Override	//AdapterView.OnItemClickListener
	public void onItemClick(AdapterView<?> parent, View convertView, int position, long id) {
		ViewHolder holder = (ViewHolder) convertView.getTag();
		if(null != holder) {
			switch(holder.mRId) {
			case R.string.settings_modify_business_detail:
				//TODO
				break;
				
			case R.string.settings_query_bill:
				//TODO
				break;
				
			case R.string.settings_publish_info:
				//TODO
				break;
				
			case R.string.settings_modify_base_info:
				//TODO
				break;
				
			default:
				break;
			}
		}
		
	}
	
	private static class ViewHolder {
		public TextView mTvSetting;
		public int mRId;
	}
	
	private class SettingAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return mSettingsId.size();
		}

		@Override
		public Object getItem(int position) {
			return mSettingsId.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if(null == convertView) {
				convertView = LayoutInflater.from(OtherActivity.this).inflate(R.layout.list_item_settings, null);
				holder = new ViewHolder();
				holder.mTvSetting = (TextView) convertView.findViewById(R.id.setting);
				
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.mRId = mSettingsId.get(position);
			holder.mTvSetting.setText(holder.mRId);
			return convertView;
		}
	}
}
